Class: fcf::Error
Package: fcfBasis
File:
bits/PartException/ErrorDecl.hpp
(
link_to_the_declaration_in_the_file
)
Implementation file:
bits/PartException/Error.ipp
(
link_to_the_implementation_in_the_file
)
Available from version: 1.0.1
Checks if the error object currently contains an error state.
The operator bool method allows you to check whether an fcf::Error object is in an error state (active) or represents a successful operation (clean).
It evaluates to true if the error member is non-zero, indicating that an error has been recorded. If the error member is null, it returns false, signifying a clean state.
Result
bool
- Returns true if an error is present, false otherwise.
Example: Checking error state
Demonstrating how to use the operator bool in conditional statements to react to errors.
#define FCF_BASIS_IMPLEMENTATION
#include <fcfBasis/basis.hpp>
#include <iostream>
int main() {
// 1. Create a clean error object
fcf::Error err;
// The error object is initially clean (operator bool returns false)
if (!err) {
std::cout << "Initial state: Error is clean." << std::endl;
}
// 2. Trigger an error state
fcf::Exception ex;
err = fcf::Error(&ex);
err.raise<fcf::LogicException>(__FILE__, __LINE__, "Something went wrong");
// 3. Check the error state using operator bool
if (err) {
std::cout << "Error state detected: " << err.error << std::endl;
} else {
std::cout << "Error state: OK." << std::endl;
}
// 4. Clear the error and check again
err.clear();
if (!err) {
std::cout << "State after clear(): Error is clean again." << std::endl;
}
return 0;
}
Output:
Initial state: Error is clean.
Error state detected: FCF_LOGIC
State after clear(): Error is clean again.
The operator bool is a convenient way to perform error checking in a single line, similar to how built-in pointers or boolean flags are used in C++.